package combine.utils;

import javax.servlet.http.Cookie;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.util.WebUtils;

public class RequestUtils
{
	public static Cookie getCookie(HttpServletRequest request, String cookieName)
	{
		return WebUtils.getCookie(request, cookieName);
	}
	
	public static void removeCookie(HttpServletResponse response, String cookieName)
	{
		Cookie cookie = new Cookie(cookieName, null);
		cookie.setMaxAge(0);
		cookie.setPath("/");
		response.addCookie(cookie);
	}
	
	public static String getRemoteAddr(HttpServletRequest request)
	{
		
		//对于nginx 适用
		String ip = request.getHeader("x-real-ip");
		
		
		if(ip == null || ip.equals(""))
		{
			ip = request.getRemoteAddr();
		}
		return ip ;
	}
}
